define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

  var Controller = {
    index: function () {
      // 初始化表格参数配置
      Table.api.init();
      this.table.first();
      this.table.second();
    },
    table: {
      first: function () {
        // 表格1
        var table1 = $("#table1");
        table1.bootstrapTable({
          url: 'wx/wximport/index',
          toolbar: '#toolbar1',
          sortName: 'id',
          search: true,
          commonSearch: false,
          escape: false,
          showToggle: false,
          showColumns: false,
          //显示导出按钮
          showExport: false,
          columns: [
            [
              {field: 'agent_id', title: 'ID'},
              {field: 'info.agent_name', title: __('代理商名称')},
              {
                field: 'operate', title: __('Operate'), table: table1, events: Table.api.events.operate, buttons: [
                  {
                    name: 'log',
                    title: '统计',
                    text: '统计',
                    icon: 'fa fa-list',
                    classname: 'btn btn-primary btn-xs btn-click',
                    click: function (e, data) {
                      $("#myTabContent2 .form-commonsearch  option[value='"+data.agent_id+"']").attr("selected", true);
                      $("#myTabContent2 .btn-refresh").trigger("click");
                    }
                  }
                ], formatter: Table.api.formatter.operate
              }
            ]
          ]
        });

        // 为表格1绑定事件
        Table.api.bindevent(table1);
      },
      second: function () {
        // 表格2
        var table2 = $("#table2");
        table2.bootstrapTable({
          url: 'wx/wximport/index2',
          extend: {
            index_url: '',
            add_url: '',
            edit_url: '',
            del_url: '',
            multi_url: '',
            table: '',
          },
          toolbar: '#toolbar2',
          sortName: 'id',
          search: false,
          escape: false,
          showToggle: false,
          showColumns: false,
          showExport: false,
          searchFormVisible: true,
          columns: [
            [
              {field: 'id', title: 'ID'},
              {field: 'type_text', title: '分类', searchList: typeList, operate: false, visible: false},
              {field: 'name', title: __('产品名称'), operate: false},
              {field: 'num', title: __('数量'), operate: false},
              {field: 'agent_id', title: __('代理商'), searchList: agentList, visible: false},
              {field: 'createtime', title: __('时间'), operate:'RANGE', addclass:'datetimerange',visible: false},
            ]
          ],
          queryParams: function (params) {
            //这里可以追加搜索条件
            var filter = JSON.parse(params.filter);
            var op = JSON.parse(params.op);
            //这里可以动态赋值，比如从URL中获取admin_id的值，filter.admin_id=Fast.api.query('admin_id');
            filter.courierBut = 1;
            op.courierBut = ">";
            params.filter = JSON.stringify(filter);
            params.op = JSON.stringify(op);
            return params;
          }
        });

        // 为表格2绑定事件
        Table.api.bindevent(table2);
      }
    },
  };
  return Controller;
});